% (* ::Package:: *)

% Low Stacks
I = eye (3109,3109);
%% NOx NO3

run Area_Reset
run Low_Reset
NOx_Low_Stack = 28761.72.*1.35.*NOx_Cal.*Low_Stack{1,1};
p = 6;
NOx_county_storage_L = zeros(3109, 3109);
NOx_county_storage_L_pm = zeros(3109, 3109);

for n = 1:S; 
    sprintf('Low Stacks: %d/%d, Loop: %d of 25.', n, S, p)
    Emission_Plus = (Low_Stack {4,1}(:,2)'+I (n,:));
    NOx (:,2) = ((Emission_Plus)*(NOx_Low_Stack))';

    run Nitrate_Sulfate_Ammonium_Marginal_New     
    run PM_25_Health

        Damages = [All_Mort{Cause,1}];
        NOx_L(n,1) = ((sum(sum(Damages)))) - B_25_Primary_MD;

        NOx_county_storage_L(n,:) = all_mort_damages_county' - all_mort_dam_cnty_base';
        NOx_county_storage_L_pm(n,:) = PM_25' - PM_25_B';
        % As of right now this will be a 3109 row vector. 
        
        clear all_mort_damages_county
    clear Damages
end
clear NOx_Low_Stack
%% Primary PM 25
PM_county_storage_L = zeros(3109, 3109);
PM_county_storage_L_pm = zeros(3109, 3109);

run Low_Reset
PM_Low_Stack = 28761.72.*(PM25_Cal.*Low_Stack {2,1});
p = 7;
for n = 1:S;
    sprintf('Low Stacks: %d/%d, Loop: %d of 25.', n, S, p)
    Emission_Plus = (Low_Stack {4,1}(:,4)'+I (n,:));
    PM_25_Primary (:,2) =((Emission_Plus)*(PM_Low_Stack))';
    
    run Nitrate_Sulfate_Ammonium_Marginal_New    
    run PM_25_Health

        Damages = [All_Mort{Cause,1}];
        PM_25_L(n,1) = ((sum(sum(Damages)))) - B_25_Primary_MD;
        
        PM_county_storage_L(n,:) = all_mort_damages_county' - all_mort_dam_cnty_base';
        PM_county_storage_L_pm(n,:) = PM_25' - PM_25_B';
        % As of right now this will be a 3109 row vector. 
        
        clear all_mort_damages_county
    clear Damages
end


%% SO2_SO4
SO2_county_storage_L = zeros(3109, 3109);
SO2_county_storage_L_pm = zeros(3109, 3109);

run Low_Reset
SO2_Low_Stack = 28761.72.*1.5.*(SO2_Cal.*Low_Stack {3,1});
p = 8;
for n = 1:S;
    sprintf('Low Stacks: %d/%d, Loop: %d of 25.', n, S, p)
    Emission_Plus = (Low_Stack {4,1}(:,5)'+I (n,:));
    SO2 (:,2) = ((Emission_Plus)*(SO2_Low_Stack))';
  
    run Nitrate_Sulfate_Ammonium_Marginal_New   
    run PM_25_Health

        Damages = [All_Mort{Cause,1}];
        SO2_L(n,1) = ((sum(sum(Damages)))) - B_25_Primary_MD;
        
        SO2_county_storage_L(n,:) = all_mort_damages_county' - all_mort_dam_cnty_base';
        SO2_county_storage_L_pm(n,:) = PM_25' - PM_25_B';
        % As of right now this will be a 3109 row vector. 
        
        clear all_mort_damages_county
    clear Damages
end

%% NH3 NH4
NH3_county_storage_L = zeros(3109, 3109);
NH3_county_storage_L_pm = zeros(3109, 3109);

run Low_Reset
NH3_Low_Stack = 28761.72.*1.06.*(NH4_Cal.*Low_Stack {5,1});
p = 9;
for n = 1:S;  
    sprintf('Low Stacks: %d/%d, Loop: %d of 25.', n, S, p)
    Emission_Plus = (Low_Stack {4,1}(:,1)'+I (n,:));
    NH3 (:,2) = ((Emission_Plus)*(NH3_Low_Stack))';    
   
    run Nitrate_Sulfate_Ammonium_Marginal_New    
    run PM_25_Health

        Damages = [All_Mort{Cause,1}];
        NH3_L(n,1) = ((sum(sum(Damages)))) - B_25_Primary_MD;
        
        NH3_county_storage_L(n,:) = all_mort_damages_county' - all_mort_dam_cnty_base';
        NH3_county_storage_L_pm(n,:) = PM_25' - PM_25_B';
        % As of right now this will be a 3109 row vector. 
        
        
        clear all_mort_damages_county
        clear Damages
end

%% VOC
VOC_county_storage_L = zeros(3109, 3109);
VOC_county_storage_L_pm = zeros(3109, 3109);

run Low_Reset
p = 10;
for n = 1:S;
    sprintf('Low Stacks: %d/%d, Loop: %d of 25.', n, S, p)
    Emission_Plus = (Low_Stack {4,1}(:,6)'+I (n,:));
    A_VOC (:,2) = (28761.72.*(Emission_Plus)*(VOC_Cal.*Low_Stack {2,1}))';    
     
run Nitrate_Sulfate_Ammonium_Marginal_New   
run PM_25_Health

    Damages = [All_Mort{Cause,1}];
    VOC_L(n,1) = ((sum(sum(Damages)))) - B_25_Primary_MD;
    VOC_county_storage_L(n,:) = all_mort_damages_county' - all_mort_dam_cnty_base';
    VOC_county_storage_L_pm(n,:) = PM_25' - PM_25_B';
    % As of right now this will be a 3109 row vector. 
        
    clear all_mort_damages_county
clear Damages
end

run Low_Reset
clear I
